home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
-
- #include <Xm/Xm.h>
- #include <Xm/Frame.h>
- #include <X11/Intrinsic.h>
- #include <X11/extensions/SGIStereo.h>
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glx.h>
- #include <GL/GLwMDrawA.h>
-
- #define Color_Buffer_Size 1
- #define Depth_Buffer_Size 1
- int sphere_slices = 16,
- sphere_stacks = 16;
- int xRot = 0, yRot = 0,
- prevy = 0, prevx = 0;
-
-
- void initCB(Widget, XtPointer, XtPointer),
- exposeCB(Widget, XtPointer, XtPointer),
- resizeCB(Widget, XtPointer, XtPointer);
- void clip_display(Display *, Window),
- nanSolidSphere(float *),
- nanWireSphere(float *);
- void start_rtn(Widget, XEvent *, String *,
- Cardinal *),
- rtn(Widget, XEvent *, String *,
- Cardinal *),
- end_rtn(Widget, XEvent *, String *,
- Cardinal *);
-
-
- main(int argc, char **argv)
- {
- XtAppContext application_context;
- Widget toplevel, glw;
- Arg args[10];
- int n = 0;
- GLXContext glw_context;
- XtTranslations trans;
- String fallback[] = {
- "*frame*shadowType: SHADOW_IN",
- "*boiler*width: 400",
- "*boiler*height: 400",
- NULL
- };
-
- char *molTranslations =
- "#override\n\
- <Btn1Down>:start_rtn() \n\
- <Btn1Motion>:rtn() \n\
- <Btn1Up>:end_rtn()\n";
-
- XtActionsRec actionsTable[] = {
- {"start_rtn", start_rtn},
- {"rtn", rtn},
- {"end_rtn", end_rtn},
- };
-
- toplevel = XtAppInitialize(&application_context, "BoilerPlate",
- (XrmOptionDescList) NULL, 0,
- &argc, (String *)argv,
- fallback, (ArgList)NULL, 0);
-
- trans = XtParseTranslationTable(molTranslations);
- XtAppAddActions(application_context, actionsTable, XtNumber(actionsTable));
-
- n=0;
- XtSetArg(args[n], GLwNrgba, TRUE); n++;
- XtSetArg(args[n], GLwNdoublebuffer, TRUE); n++;
- XtSetArg(args[n], GLwNredSize, Color_Buffer_Size); n++;
- XtSetArg(args[n], GLwNgreenSize, Color_Buffer_Size); n++;
- XtSetArg(args[n], GLwNblueSize, Color_Buffer_Size); n++;
- XtSetArg(args[n], GLwCDepthSize, Depth_Buffer_Size); n++;
-
- glw = XtCreateWidget("boiler", glwMDrawingAreaWidgetClass,
- toplevel, args, n);
-
- XtAddCallback(glw, GLwNginitCallback, initCB, &glw_context);
- XtAddCallback(glw, GLwNexposeCallback, exposeCB, &glw_context);
- XtAddCallback(glw, GLwNresizeCallback, resizeCB, &glw_context);
-
- XtOverrideTranslations(glw, trans);
- XtManageChild(glw);
-
- XtRealizeWidget(toplevel);
- XtAppMainLoop(application_context);
- }
-
- void
- initCB(Widget w, XtPointer client_data, XtPointer call_data)
- {
- Display *display = XtDisplay(w);
- int screen = DefaultScreen(display);
- Window window = XtWindow(w);
- XVisualInfo *vi;
- GLXContext *glw_context = (GLXContext *) client_data;
- Arg args[10];
-
- XtSetArg(args[0], GLwNvisualInfo, &vi);
- XtGetValues(w, args, 1);
-
- *glw_context = glXCreateContext(display, vi, None, GL_TRUE);
- glXMakeCurrent(display, window, *glw_context);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(30.0, 1.0, .25, 15.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- glXSwapBuffers(display, window);
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glLineWidth(2.0);
- clip_display(display, window);
- }
-
- void
- exposeCB(Widget w, XtPointer client_data, XtPointer call_data)
- {
- Display *display = XtDisplay(w);
- Window window = XtWindow(w);
- GLXContext *glw_context = (GLXContext *) client_data;
-
- glXMakeCurrent(display, window, *glw_context);
- clip_display(display, window);
- }
-
- void
- resizeCB(Widget w, XtPointer client_data, XtPointer call_data)
- {
- Display *display = XtDisplay(w);
- Window window = XtWindow(w);
- GLXContext *glw_context = (GLXContext *) client_data;
- GLwDrawingAreaCallbackStruct *Call_Data =
- (GLwDrawingAreaCallbackStruct *) call_data;
-
- glXMakeCurrent(display, window, *glw_context);
- glViewport(0, 0,
- (GLuint) Call_Data->width-1,
- (GLuint) Call_Data->height-1);
-
- clip_display(display, window);
- }
-
-
- void clip_display(Display *d, Window w)
- {
- static float x = 0.0;
- GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0};
- GLdouble eqn2[4] ={1.0, 0.0, 0.0, 0.0};
- float params[4] = {0.0, 0.0, 0.0, 1.0};
-
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-
- glColor3f(1.0, 1.0, 1.0);
- glPushMatrix();
- glTranslatef(0.0, 0.0, -5.0);
-
- glClipPlane(GL_CLIP_PLANE0, eqn);
- glEnable(GL_CLIP_PLANE0);
- glPushMatrix();
- glRotatef(x += 5, 1.0, 0.0, 0.0);
- glClipPlane(GL_CLIP_PLANE1, eqn2);
- glEnable(GL_CLIP_PLANE1);
- glPopMatrix();
-
- glRotatef(90., 1.0, 0.0, 0.0);
-
- nanWireSphere(params);
- glPopMatrix();
- glFlush();
- glXSwapBuffers(d, w);
- }
-
- void nanSolidSphere(float *params)
- {
- static GLUquadricObj *quadObj;
- static int entry = 0;
- double radius;
-
- radius = params[3];
- glEnable(GL_COLOR_MATERIAL);
- glPushMatrix();
- glTranslatef(params[0], params[1], params[2]);
- if (!entry)
- {
- quadObj = gluNewQuadric ();
- gluQuadricDrawStyle (quadObj, GLU_FILL);
- gluQuadricOrientation(quadObj, GLU_OUTSIDE);
- gluQuadricNormals (quadObj, GLU_SMOOTH);
- }
- gluSphere (quadObj, radius, sphere_slices, sphere_stacks);
- glPopMatrix();
- glDisable(GL_COLOR_MATERIAL);
- }
-
- void nanWireSphere(float *params)
- {
- static GLUquadricObj *quadObj;
- static int entry = 0;
- double radius;
-
- radius = params[3];
- glEnable(GL_COLOR_MATERIAL);
- glPushMatrix();
- glTranslatef(params[0], params[1], params[2]);
- if (!entry)
- {
- quadObj = gluNewQuadric ();
- gluQuadricDrawStyle (quadObj, GLU_LINE);
- gluQuadricOrientation(quadObj, GLU_OUTSIDE);
- gluQuadricNormals (quadObj, GLU_SMOOTH);
- }
- gluSphere (quadObj, radius, sphere_slices, sphere_stacks);
- glPopMatrix();
- glDisable(GL_COLOR_MATERIAL);
- }
-
- void start_rtn(Widget w, XEvent *event, String *s, Cardinal *c)
- {
- prevx = event->xbutton.x;
- prevy = event->xbutton.y;
- }
-
- void rtn(Widget w, XEvent *event, String *s, Cardinal *c)
- {
- int x = event->xbutton.x;
- int y = event->xbutton.y;
-
- yRot += 5 * (x - prevx);
- xRot += 5 * (y - prevy);
- prevx = x;
- prevy = y;
- glPushMatrix();
- glRotatef(xRot*0.1, 1.0, 0.0, 0.0);
- glRotatef(yRot*0.1, 0.0, 1.0, 0.0);
- clip_display(XtDisplay(w), XtWindow(w));
- glPopMatrix();
- }
-
- void
- end_rtn(Widget w, XEvent *event, String *s, Cardinal *c)
- {
- glPushMatrix();
- glRotatef(xRot*0.1, 1.0, 0.0, 0.0);
- glRotatef(yRot*0.1, 0.0, 1.0, 0.0);
- clip_display(XtDisplay(w), XtWindow(w));
- glPopMatrix();
- }
-